package com.liug.droidsmall2.activity;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

import com.liug.droidsmall2.MainActivity;
import com.liug.droidsmall2.R;

import me.weyye.hipermission.HiPermission;
import me.weyye.hipermission.PermissionCallback;

public class SplashActivity extends AppCompatActivity {

    private VideoView video_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        video_view = (VideoView) findViewById(R.id.video_view);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        video_view.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/raw/vv"));



        HiPermission.create(SplashActivity.this)
                .title("尊敬的用户")
                .filterColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, getTheme()))//图标的颜色
                .msg("为了您正常使用软件功能，请打开下列权限！\n谢谢您的配合！")
                .style(R.style.PermissionBlueStyle)
                .checkMutiPermission(new PermissionCallback() {
                    @Override
                    public void onClose() {
                        Log.i("onClose", "onClose");
                    }

                    @Override
                    public void onFinish() {
                    }

                    @Override
                    public void onDeny(String permisson, int position) {
                        Log.i("onClose", "onDeny");
                    }

                    @Override
                    public void onGuarantee(String permisson, int position) {
                        Log.i("onClose", "onGuarantee");
                    }
                });


        startActivity(new Intent(SplashActivity.this, MainActivity.class));
        finish();



        MediaController mediaController = new MediaController(this);
        mediaController.setVisibility(View.GONE); //设置隐藏
        video_view.setMediaController(mediaController);
        mediaController.setMediaPlayer(video_view);// 设置MediaController与VideView建立关联
        video_view.start();// 开始播放

        video_view.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
               startActivity(new Intent(SplashActivity.this, MainActivity.class));
                finish();
            }
        });
    }
}
